package com.cskaoyan.controller;

import com.cskaoyan.bean.User;
import com.cskaoyan.bean.User2;
import com.cskaoyan.bean.User3;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * @author stone
 * @date 2022/05/30 15:52
 */
@RestController
public class UserController {

    // localhost:8080/login1?username=songge&password=niupi
    // localhost:8080/login1?username=songge&password=niupi&age=25
    @RequestMapping("login1")
    public String login1(String username,String password,int age) {
        return "ok";
    }
    // localhost:8080/login2?username=songge&password=niupi
    // localhost:8080/login2?username=songge&password=niupi&age=25
    @RequestMapping("login2")
    public String login2(String username,String password,Integer age) {
        return "ok";
    }

    // localhost:8080/login3?username=songge&password=niupi&age=25
    // &hobbys=sing&hobbys=dance&hobbys=rap&ids=1&ids=2&ids=3
    @RequestMapping("login3")
    public String login3(String username,String password,Integer age,String[] hobbys,Integer[] ids) {
        return "ok";
    }
    // 以默认的日期格式来接收
    // localhost:8080/login4?username=songge&password=niupi&age=25
    // &hobbys=sing&hobbys=dance&hobbys=rap&ids=1&ids=2&ids=3
    // &birthday=2022/05/30
    @RequestMapping("login4")
    public String login4(String username, String password, Integer age,
                         String[] hobbys, Integer[] ids,
                         Date birthday) {
        return "ok";
    }

    // 以指定的日期格式来接收
    // localhost:8080/login5?username=songge&password=niupi&age=25
    // &hobbys=sing&hobbys=dance&hobbys=rap&ids=1&ids=2&ids=3
    // &birthday=2022-05-30
    @RequestMapping("login5")
    public String login5(String username, String password, Integer age,
                         String[] hobbys, Integer[] ids,
                         @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday) {
                         //@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date birthday) {
        return "ok";
    }


    // 请求参数名和成员变量名一致
    // 该请求和login5一模一样，请求url不一样login6
    // localhost:8080/login6?username=songge&password=niupi&age=25
    // &hobbys=sing&hobbys=dance&hobbys=rap&ids=1&ids=2&ids=3
    // &birthday=2022-05-30
    @RequestMapping("login6")
    public String login6(User user) {
        return "ok";
    }

    @RequestMapping("user/list")
    public String list(User2 user){
        return "ok";
    }

    @RequestMapping("login7")
    public String login7(@RequestBody User3 user3) {
        return "ok";
    }
    @RequestMapping("login8")
    public String login8(@RequestBody Map map) {
        return "ok";
    }
}
